package edu.csl.study.coreserver2.hystrix;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import edu.csl.study.coreserver2.vo.User;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

@Service
public class ServiceWithHystrix {
    // 单独使用，需要在配置类加@EnableHystrix支持
    @HystrixCommand(fallbackMethod = "getUserHystrixCallback")
    public String getUser(int id) {
        if(id == 1){
            return " user - 正常用户";
        }else{
            throw new RuntimeException("用户ID错误");
        }
    }
    public String getUserHystrixCallback(int id,Throwable throwable) {

            return " user 失败后-默认的用户";

    }

}